class Enum {
    list = new Array();
    /**
     * 添加枚举字段
     * field: 枚举字段
     * label: 界面显示
     * value: 枚举值
     */
    add(label, value) {
        this.list.push({ label, value })
        return this
    }

    /**
     * 根据枚举value获取其label
     */
    getLabelByValue(value) {
        // 字段不存在返回‘’
        if (value === undefined || value === null) {
            return ''
        }
        for (let index = 0; index < this.list.length; index++) {
            const element = this.list[index];
            if (element.value === value) {
                return element.label
            }
        }
        return ''
    }
}

var questions = new Enum()
questions.add("单选题", "RADIO_QUESTION")
questions.add("多选题", "MULTI_SELECT_QUESTION")
questions.add("判断题", "TRUE_FALSE_QUESTION")
questions.add("简答题", "SHORT_ANSWER_QUESTION")

var Constants = {
    QuestionType: questions
}

export default Constants